﻿using System;
using System.Collections.Generic;
using DataStore.Domain;
using NHibernate;
using NHibernate.Linq;
using System.Linq;

namespace DataStore.Repositories
{
    public class CatalogItemRepository : IRepository<CatalogItem>
    {
        readonly UnitOfWork _unitOfWork;

        public CatalogItemRepository(UnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }

        public CatalogItem Get(object id)
        {
            throw new NotImplementedException();
        }

        public void Delete(CatalogItem entity)
        {
            ISession session = _unitOfWork.Session;
            session.Delete(entity);
        }

        public void DeleteAll()
        {
            throw new NotImplementedException();
        }

        public void Save(CatalogItem entity)
        {
            ISession session = _unitOfWork.Session;
            session.Save(entity);
        }

        public CatalogItem SaveOrUpdate(CatalogItem entity)
        {
            ISession session = _unitOfWork.Session;
            session.SaveOrUpdate(entity);
            return entity;
        }

        public void Update(CatalogItem catalogItem)
        {
            ISession session = _unitOfWork.Session;
            session.Update(catalogItem);
        }

        IEnumerable<CatalogItem> IRepository<CatalogItem>.All
        {
            get
            {
                ISession session = _unitOfWork.Session;
                return session.Linq<CatalogItem>().ToList();
            }
        }

        public bool Exists(CatalogItem entity)
        {
            throw new NotImplementedException();
        }

        public bool IsEmpty
        {
            get { throw new NotImplementedException(); }
        }

        public int Count(CatalogItem entity)
        {
            throw new NotImplementedException();
        }

        public int CountAll()
        {
            throw new NotImplementedException();
        }
    }
}
